


        var watchCheck = null;
        $(document).ready(function(){
            $(window).scroll(function(){
                /*var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
                if(!scrollTop){
                    $('header nav').removeClass('addBg');
                }else{
                    $('header nav').addClass('addBg');
                }*/
                
            })
            var srchArr = sessionStorage.getItem('lastSearch').split(',');
            var proId = srchArr[0];
            var cityId = srchArr[1];
            var tradeId = srchArr[3];
            var type = srchArr[4];
            var proObj = {
                id:proId
            };
            var compName = [];
            compName.length = 4;
            for(var n = 0;n < $('#compType').siblings('ul').find('li').length;n++){
                if($('#compType').siblings('ul').find('li').eq(n).attr('data-id') == type){
                    $('#compType').val($('#compType').siblings('ul').find('li').eq(n).text());
                    compName.splice(3,1,$('#compType').siblings('ul').find('li').eq(n).text());
                    break;
                }
            }
            if($('.check').length){ 
                $('#name').val(srchArr[2]);
                compName.splice(1,1,srchArr[2]);
                
            }else{
                var size = srchArr[2];
                nameArr = sessionStorage.getItem('compName').split(',');
                compName.splice(1,1,'compName');
                for(var n = 0;n < $('#nums').siblings('ul').find('li').length;n++){
                    if($('#nums').siblings('ul').find('li').eq(n).attr('data-id') == size){
                        $('#nums').val($('#nums').siblings('ul').find('li').eq(n).text());
                        break;
                    }
                }
            }
            function writeNames(arr){
                for(var i = 0;i < arr.length;i++){
                    var item = "<div class='item'><p>" + $('#area').val() + "<span class='nameVal'>" + arr[i] +"</span>" + $('#trade').val() + $('#compType').val() + "</p><p class='lvl'>高</p></div>";
                    $('main .result .contn .list').append(item);
                    
                }
            }
            watchCheck = setInterval(function(){
                for(var c = 0;c < compName.length;c++){
                    if(!compName[c]) return false;
                }
                if($('.check').length){
                    $('main .result .check .rstTtl span').text(compName.join(''));
                }else{
                    writeNames(nameArr);
                }
                
                
                clearInterval(watchCheck);
            })
            $.ajax({
                type: "POST",
                url: realm + "/api/getCityList",
                data: JSON.stringify(proObj),
                dataType: "json",
                contentType: 'application/json',
                success: function(data){
                    
                    var list = data.data;
                    for(var n = 0;n < list.length;n++){
                        if(list[n].id == cityId){
                            $('#area').attr('data-id',cityId),
                            $('#area').val(list[n].name);
                            compName.splice(0,1,list[n].name);
                            break;
                        }
                    }
                },
                error:function(data){
                    console.log(data);
                }
            })

            $.ajax({
                type: "GET",
                url: realm + "/api/getTradeList",
                data: {},
                dataType: "json",
                contentType: 'application/json',
                success: function(data){
                    trade = data.data;
                    for(var t = 0;t < trade.length;t++){
                        for(var n = 0;n < trade[t].tradeList.length;n++){
                            if(trade[t].tradeList[n].id == tradeId){
                                $('#trade').attr('data-id',tradeId);
                                $('#trade').val(trade[t].tradeList[n].name);
                                compName.splice(2,1,trade[t].tradeList[n].name);
                                return false;
                            }
                        }
                    }
                },
                error:function(data){
                    console.log(data);
                }
            });
            
            $('main .pageHead .content form .submit').click(function(){
                var pass = true;
                for(var i = 0;i < $('main .pageHead .content form input').length;i++){
                    var val = $('main .pageHead .content form input').eq(i).val();
                    if(val.length == 0){
                        if($('main .pageHead .content form input').eq(i).parent()[0].className.indexOf('hidden') >= 0) continue;
                        if($('main .pageHead .content form input').eq(i).attr('id') == 'name'){
                            alert('请输入字号')
                        }else{
                            alert('请选择' + $('main .pageHead .content form input').eq(i).siblings('span').text());
                        }
                        pass = false;
                        break;
                    }
                    if($('main .pageHead .content form input').eq(i).attr('id') == 'name'){
                        var regExp = /^[\u4e00-\u9fa5]+$/;
                        if(!val.match(regExp)){
                            alert('字号必须为简体汉字');
                            pass = false;
                            break;
                        }                
                    }
                }
                if(pass){
                    var obj = {
                        cityId:$('#area').attr('data-id'),
                        keyword:$('#name').val(),
                        name:sessionStorage.getItem('checkerName'),
                        phone:sessionStorage.getItem('checkerNumber'),
                        tradeId:$('#trade').attr('data-id'),
                        recordType:$('header nav .links .active').text() != '公司核名'?'1':'2',
                        type:$('#compType').attr('data-id')
                    }
                    if(obj.recordType == '1'){
                        delete obj.keyword;
                        obj.size = $('#nums').attr('data-id');
                    }
                    $.ajax({
                        type: "POST",
                        url: realm + "/api/toNaming",
                        data: JSON.stringify(obj),
                        dataType: "json",
                        contentType: 'application/json',
                        success: function(data){
                            if(data.message == "核名成功"){
                                var newName = '';
                                for(var n = 0;n < $('main .pageHead .content form .form-group input').length;n++){
                                    if($('main .pageHead .content form .form-group input').eq(n).parent()[0].className.indexOf('hidden') >= 0) continue;
                                    newName += $('main .pageHead .content form .form-group input').eq(n).val();
                                }
                                $('main .result .check .rstTtl span').text(newName);
                            }else if(data.message == "起名成功"){
                                nameArr = [];
                                for(var a = 0;a < data.data.length;a++){
                                    nameArr.push(data.data[a].name);
                                }
                                $('main .result .contn .list').empty();
                                writeNames(nameArr);
                            }
                        },
                        error:function(data){
                            console.log(data);
                        }
                    })
                }
            })
            
        })